package com.coocaa.x.app.liteplayer;

import com.coocaa.x.service.XServiceManager;
import com.coocaa.x.service.litecontent.LiteContentServiceConnecter;

import android.app.Activity;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        XServiceManager.init(this);
        new Thread() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                LiteContentServiceConnecter.init();
            }

        }.start();
        LinearLayout root = new LinearLayout(this);

        Button btn1 = new Button(this);
        btn1.setWidth(200);
        btn1.setHeight(150);
        btn1.setText("测试获取本地app");
        btn1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                testUpdateData();
            }
        });
        root.addView(btn1);
        setContentView(root);
    }

    private void testApp() {
        try {
            Log.d("app", "btn click!!" + LiteContentServiceConnecter.getService());
            String json = LiteContentServiceConnecter.getService().call("apps://com.coocaa.app/installed_apps?order=nb&filter=mine");
            Log.d("app", "json:" + json);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void testUpdateData() {
        new Thread() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                try {
                    Log.d("app", "btn click!!  getupdate data");
                    String json = LiteContentServiceConnecter.getService().call("apps://com.coocaa.app/update_apps");
                    Log.d("app", "json:" + json);
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }.start();
    }


}
